﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace XDMasterNetPlayer
{
    public partial class ConfigInfo : Form
    {
        private string strLocalPort = "LocalPort";
        private string strRemotePort = "RemotePort";
        private string strRemoteIP = "RemoteIP";
        private string strSlaverIP = "SlaverIP";
        private string strLocalPlayerPort = "LocalPlayerPort";
        private string strSlaverPort = "SlaverPort";
        private string strLeftIdleMovie = "LeftIdleMovie";
        private string strRightIdleMovie = "RightIdleMovie";
        private string strMovieExt = "MovieExt";
        private string strLeftImage = "LeftImage";
        private string strGradImage = "GradImage";
        public int nLocalPort;
        public int nRemotePort;
        public string RemoteIP;

        public string SlaverIP;
        public int nLocalPlayerPort;
        public int nSlaverPort;

        public string RightIdleMovie;
        public string LeftIdleMovie;
        public string MovieExt;
        public string LeftImage;
        public string GradImage;
        public ConfigInfo()
        {
            InitializeComponent();
        }
        public void LoadData()
        {
            XMLHelper xmlhelper = new XMLHelper();
            xmlhelper.FilePath = Directory.GetCurrentDirectory() + "\\XDMasterNetPlayer.xml";
            textBoxPort.Text = xmlhelper.GetNodeValue(strLocalPort);
            textBox_RemoteIP.Text = xmlhelper.GetNodeValue(strRemoteIP);
            textBox_RemotePort.Text = xmlhelper.GetNodeValue(strRemotePort);
            if (textBoxPort.Text != null || textBoxPort.Text != "")
            {
                nLocalPort = int.Parse(textBoxPort.Text);
            }
            if (textBox_RemotePort.Text != null || textBox_RemotePort.Text != "")
            {
                nRemotePort = int.Parse(textBox_RemotePort.Text);
            }
           
            RemoteIP = xmlhelper.GetNodeValue(strRemoteIP);
            RightIdleMovie = xmlhelper.GetNodeValue(strRightIdleMovie);
            LeftIdleMovie = xmlhelper.GetNodeValue(strLeftIdleMovie);
            MovieExt = xmlhelper.GetNodeValue(strMovieExt);
            SlaverIP = xmlhelper.GetNodeValue(strSlaverIP);
            string temp = xmlhelper.GetNodeValue(strLocalPlayerPort);
            if (temp != null)
            {
                nLocalPlayerPort = int.Parse(temp);
            }
            temp = xmlhelper.GetNodeValue(strSlaverPort);
            if (temp != null)
            {
                nSlaverPort = int.Parse(temp);
            }
            LeftImage = xmlhelper.GetNodeValue(strLeftImage);
            GradImage = xmlhelper.GetNodeValue(strGradImage);
        }
        private void ConfigInfo_Load(object sender, EventArgs e)
        {
            XMLHelper xmlhelper = new XMLHelper();
            xmlhelper.FilePath = Directory.GetCurrentDirectory() + "\\XDMasterNetPlayer.xml";
            textBoxPort.Text = xmlhelper.GetNodeValue(strLocalPort);
            textBox_RemoteIP.Text = xmlhelper.GetNodeValue(strRemoteIP);
            textBox_RemotePort.Text = xmlhelper.GetNodeValue(strRemotePort);

            if (textBoxPort.Text != null || textBoxPort.Text != "")
            {
                nLocalPort = int.Parse(textBoxPort.Text);
            }
            if (textBox_RemotePort.Text != null || textBox_RemotePort.Text != "")
            {
                nRemotePort = int.Parse(textBox_RemotePort.Text);
            }
            RemoteIP = textBox_RemoteIP.Text;
            RightIdleMovie = xmlhelper.GetNodeValue(strRightIdleMovie);
            LeftIdleMovie = xmlhelper.GetNodeValue(strLeftIdleMovie);
            MovieExt = xmlhelper.GetNodeValue(strMovieExt);
            SlaverIP = xmlhelper.GetNodeValue(strSlaverIP);
            string temp = xmlhelper.GetNodeValue(strLocalPlayerPort);
            if (temp != null)
            {
                nLocalPlayerPort = int.Parse(temp);
            }
            temp = xmlhelper.GetNodeValue(strSlaverPort);
            if (temp != null)
            {
                nSlaverPort = int.Parse(temp);
            }
            LeftImage = xmlhelper.GetNodeValue(strLeftImage);
            GradImage = xmlhelper.GetNodeValue(strGradImage);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            XMLHelper xmlhelper = new XMLHelper();
            xmlhelper.FilePath = Directory.GetCurrentDirectory() + "\\XDMasterNetPlayer.xml";
            xmlhelper.OpenXML();
            xmlhelper.SetXmlNodeValue(strLocalPort, textBoxPort.Text);
            xmlhelper.SetXmlNodeValue(strRemoteIP, textBox_RemoteIP.Text);
            xmlhelper.SetXmlNodeValue(strRemotePort, textBox_RemotePort.Text);
            nLocalPort = int.Parse(textBoxPort.Text);
            nRemotePort = int.Parse(textBox_RemotePort.Text);
            RemoteIP = textBox_RemoteIP.Text;
            xmlhelper.SavexmlDocument();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            XMLHelper xmlhelper = new XMLHelper();
            xmlhelper.FilePath = Directory.GetCurrentDirectory() + "\\XDMasterNetPlayer.xml";
            xmlhelper.CreatexmlDocument(xmlhelper.FilePath, "XDMasterNetPlayerConfig", "gb2312");
            xmlhelper.AddParentNode("Net");
            xmlhelper.AddChildNode("Net", strLocalPort);
            xmlhelper.SetXmlNodeValue(strLocalPort, "8002");
            xmlhelper.AddChildNode("Net", strRemotePort);
            xmlhelper.SetXmlNodeValue(strRemotePort, "8004");
            xmlhelper.AddChildNode("Net", strRemoteIP);
            xmlhelper.SetXmlNodeValue(strRemoteIP, "192.168.1.100");
            xmlhelper.AddParentNode("Movie");
            xmlhelper.AddChildNode("Movie", strLeftIdleMovie);
            xmlhelper.AddChildNode("Movie", strRightIdleMovie);
            xmlhelper.AddChildNode("Movie", strMovieExt);
            xmlhelper.SetXmlNodeValue(strLeftIdleMovie, "\\Movies\\AQ_L.mov");
            xmlhelper.SetXmlNodeValue(strRightIdleMovie, "\\Movies\\AQ_R.mov");
            xmlhelper.SetXmlNodeValue(strMovieExt, ".mpg");
            
            xmlhelper.AddParentNode("PlayerNet");
            xmlhelper.AddChildNode("PlayerNet", strLocalPlayerPort);
            xmlhelper.SetXmlNodeValue(strLocalPlayerPort, "9002");
            xmlhelper.AddChildNode("PlayerNet", strSlaverPort);
            xmlhelper.SetXmlNodeValue(strSlaverPort, "9003");
            xmlhelper.AddChildNode("PlayerNet", strSlaverIP);
            xmlhelper.SetXmlNodeValue(strSlaverIP, "192.168.1.81");

            xmlhelper.AddChildNode("Movie", strLeftImage);
            xmlhelper.SetXmlNodeValue(strLeftImage, "\\Image\\tree_left.jpg");
            xmlhelper.AddChildNode("Movie", strGradImage);
            xmlhelper.SetXmlNodeValue(strGradImage, "\\Image\\grad.png");
            xmlhelper.SavexmlDocument();

        }


    }
}
